﻿package com.cf.core.media{
	public class covertIMG{
		
	}//class
}//package



/**********************

package classes.quietless.utils {
	
    import flash.display.Sprite;
    import flash.display.DisplayObject;
    import flash.geom.Matrix;	
	import flash.display.BitmapData;
	import flash.utils.ByteArray;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	
	import classes.quietless.events.CustomEvent;
	import classes.adobe.images.*;
	import classes.marston.utils.URLRequestWrapper;
	
	public class DynamicBitmap extends Sprite {
		
		private var _target:DisplayObject;
		private var _image:ByteArray;
		private var _filename:String; 
			
		public function DynamicBitmap($targ:DisplayObject, $name:String)
		{
		    var bmd:BitmapData = new BitmapData($targ.width, $targ.height, true, 0xFFFFFF);
				bmd.draw($targ, new Matrix(), null, null, null, false);
		    
			_target = $targ; _filename = $name;
			var ext:String = $name.substr(-3);
			if (ext=='png') {
				_image = PNGEncoder.encode(bmd);
			}	else if (ext=='jpg'){
				_image = new JPGEncoder().encode(bmd);
			}
		}
		
		public function upload($script:String, $directory:String=null, $args:Object=null):void
		{
		    if (!_image) {
		        dispatchEvent(new CustomEvent('ImageConversionFailure', _target+' could not be converted to BitmapData\n\n'+'***make sure file extension is either .jpg or .png***')); return;
	        }
		    var wrapper = new URLRequestWrapper(_image, _filename, $directory, $args);
		        wrapper.url = $script;
            var ldr:URLLoader = new URLLoader();
                ldr.dataFormat = URLLoaderDataFormat.BINARY;
                ldr.addEventListener(Event.COMPLETE, onLoadSuccess);
                ldr.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
                ldr.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
                ldr.load(wrapper.request);
		}
			
//----------------------------------------------------------------//

		private function onLoadSuccess(evt:Event):void
		{
			dispatchEvent(new CustomEvent('onLoadSuccess', evt.target));
		}
		
		private function ioErrorHandler(evt:IOErrorEvent):void
		{
			dispatchEvent(new CustomEvent('onLoadFailure', 'Attempt to upload '+_target+' as Bitmap failed, check network connection.'));
		}
		
		private function onSecurityError(evt:SecurityErrorEvent):void
		{
			dispatchEvent(new CustomEvent('onSecurityError', 'A Flash Player security violation has occurred'));
		}

//----------------------------------------------------------------//	
	    
	
		
	}
	
}








//****/